<?php

namespace App\Http\Controllers\Mobile;

use App\Model\Move_task;
use App\Model\Workflow_desc;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

//人员调动
class Staff_moveController extends CommonController
{
    //
	protected $Move_task;
	protected $Workflow_desc;
	protected static $uid;
	public function __construct()
	{
		parent::__construct();
		$this->Move_task=new  Move_task();
		$this->Workflow_desc=new Workflow_desc();
		self::$uid=Auth::user()->id;

	}




// 人员调动首页
	public function index(){
		$data=$this->Workflow_desc->move_lists(self::$uid);
		foreach($data as $kk=>$vv){
			if($vv['status']==1){
				$Arr['stay_trial'][]=$vv;
			}else{
				$Arr['rial'][]=$vv;
			}

		}
		$result=[];
		$newArr=[];
		if(isset($Arr['stay_trial'])){
			foreach($Arr['stay_trial'] as $k=>$v){
				$result[$k]['to_store_name']=$v['move_task']['store']['name'];
				$result[$k]['to_store_station_name']=$v['move_task']['store_station']['name'];
				$result[$k]['start_day']=$v['move_task']['start_day'];
				$result[$k]['end_day']=$v['move_task']['end_day'];
				$result[$k]['start_time']=$v['move_task']['start_time'];
				$result[$k]['end_time']=$v['move_task']['end_time'];
				$result[$k]['created']=date("Y-m-d",strtotime($v['created_at']));
			}
		}

		if(isset($Arr['rial'])){
			foreach($Arr['rial'] as $key=>$value){
				if($value['move_task']['is_agree']==3){
					$newArr[$key]['from_store_name']=null;
					$newArr[$key]['from_staff_name']=null;
					$newArr[$key]['status']='不通过';
				}
				if($value['move_task']['is_agree']==2){
					$newArr[$key]['from_store_name']=$value['move_task']['from_store']['name'];
					$newArr[$key]['from_staff_name']=$value['move_task']['from_staff']['name'];
					$newArr[$key]['status']='已调动';
				}
				$newArr[$key]['to_store_name']=$value['move_task']['store']['name'];
				$newArr[$key]['to_store_station_name']=$value['move_task']['store_station']['name'];
				$newArr[$key]['start_day']=$value['move_task']['start_day'];
				$newArr[$key]['end_day']=$value['move_task']['end_day'];
				$newArr[$key]['start_time']=$value['move_task']['start_time'];
				$newArr[$key]['end_time']=$value['move_task']['end_time'];
				$newArr[$key]['created']=date("Y-m-d",strtotime($value['created_at']));
			}
		}

		$str['rial']=$newArr;
		$str['stay_trial']=$result;

		return $this->success($str);
	}
//	发起调动
	public function add_move(Request $request){
		$data=$request->input();
		$data['status']=1;
		$data['type']=2;
		try{
			$data=$this->Move_task->create($data);
		}catch (\Exception $exception){
			$message=$exception->getMessage();
		}
		if(!isset($message)){
			return $this->stored($data);
		}else{
			return $this->failed($message);
		}
	}


//	调出部门
	public function all_store(){
		$userData=$this->add_move();
		return $userData;
	}



//	调出人员
	public function move_staff(){

		return 1;
	}



//	支援岗位
	public function store_stations(){

		return 1;
	}



}
